//
//  HACChartNode.h
//  HStockCharts
//
//  Created by Hotacool on 2018/9/18.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <HStockCharts/HStockCharts.h>

@interface HACChartNode : NSObject <HACAxisProvider>
@property (nonatomic, weak) CALayer *hostLayer;
@property (nonatomic, assign) CGRect relativeFrame;
/** x轴分割线数 */
@property (nonatomic) NSInteger xAxisCount;
/** y轴分割线数 */
@property (nonatomic) NSInteger yAxisCount;
/** 数据点显示rect */
@property (nonatomic, assign) CGRect pointRect;
/** 是否实心 */
@property (nonatomic) BOOL isSoildFill;
/** 起始index，按照0方式计数 */
@property (nonatomic) NSInteger startIndex;
/** 实际结束的index */
@property (nonatomic) NSInteger endIndex;
/** 当前实际数据（数组的count） */
@property (nonatomic, readonly) NSInteger actualCount;
/** 当前绘图区域需要显示的数目，分时的值是固定，k线的值会跟随放大，缩小手势变化,用于计算x坐标*/
@property (nonatomic) NSInteger visualCount;
/** 单个宽度,由visualCount和frame决定 */
@property (nonatomic) CGFloat singleWidth;
/** 间隙,默认1，可以间接控制rect宽度singleWidth - itemsSpace， */
@property (nonatomic) CGFloat itemsSpace;
@property (nonatomic) CGFloat maxValue;/** 所有数据中最大值，包括指标(用于确定绘图上下边界) */
@property (nonatomic) CGFloat minValue;/** 所有数据中最小值，包括指标(用于确定绘图上下边界) */
@property (nonatomic, strong) HACChartData *data;

/** 基本数据 */
@property (nonatomic, strong) HACBasicInfoEntry *basicInfoData;
/// the object representing the left y-axis
@property (nonatomic, strong) HACAxisComponents *leftAxis;
/// the object representing the right y-axis
@property (nonatomic, strong) HACAxisComponents *rightAxis;

- (instancetype)initWithHostLayer:(CALayer*)layer;

- (void)refreshData:(HACChartData*)data;

- (void)clearNode;

- (void)setNeedsDisplay;

- (void)removeNode;

- (void)setUp;

- (void)updateFrame;

- (CGFloat)maxContentWidth ;

#pragma mark -- api for interaction
- (NSInteger)indexAtChartForCoordinate:(CGPoint)point ;

- (CGPoint)pointAtChartForIndex:(NSInteger)index ;

- (HACChartDataEntry*)dataAtChartForCoordinate:(CGPoint)point ;

- (HACChartDataEntry*)dataAtChartForIndex:(NSUInteger)index ;

#pragma mark -- common caculate method
- (NSString *)stringForAxisTextItem:(HACAxisComponents *)axisItem;

- (NSInteger)relativeIdxFromIndex:(NSInteger)i ;

- (CGFloat)xPointForIndex:(NSInteger)index inRect:(CGRect)rect ;

- (CGFloat)calculatorYForValue:(CGFloat)value min:(CGFloat)min max:(CGFloat)max inRect:(CGRect)rect ;
@end
